package com.wzt.config;


import com.wzt.service.FunctionAssistant;
import com.wzt.service.InvoiceHandler;
import dev.langchain4j.agent.tool.ToolSpecification;
import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.service.AiServices;
import dev.langchain4j.service.tool.ToolExecutor;
import dev.langchain4j.service.tool.ToolProviderRequest;
import dev.langchain4j.service.tool.ToolProviderResult;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static dev.langchain4j.agent.tool.JsonSchemaProperty.description;
import static dev.langchain4j.agent.tool.JsonSchemaProperty.type;
import java.util.Map;

import java.util.Map;



@Configuration(proxyBeanMethods = false)
public class ChatLanguageModelConfig
{
    @Bean
    public ChatLanguageModel chatLanguageModel()
    {
        return OpenAiChatModel.builder()
                .apiKey(System.getenv("LANGCHAIN4J_KEY"))
                .modelName("qwen-turbo-0624")
                .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
                .build();
    }

//    @Bean
//    public FunctionAssistant functionAssistant(ChatLanguageModel chatLanguageModel) {
//        // 工具说明 ToolSpecification------定义 类似实体类
//        ToolSpecification toolSpecification = ToolSpecification.builder()
//                .name("invoice_assistant")
//                .description("根据用户提交的开票信息，开具发票")
//                .addParameter("companyName", type("string"), description("公司名称"))
//                .addParameter("dutyNumber", type("string"), description("税号"))
//                .addParameter("amount", type("string"), description("金额，保留两位有效数字"))
//                .build();
//
//        // 业务逻辑 ToolExecutor------干活
//        ToolExecutor toolExecutor = (toolExecutionRequest, memoryId) -> {
//            System.out.println(toolExecutionRequest.id());
//            System.out.println(toolExecutionRequest.name());
//            String arguments1 = toolExecutionRequest.arguments();
//            System.out.println("arguments1 =>>>> " + arguments1);//调用我们第三方接口
//            return "开具成功";
//        };
//
//        return AiServices.builder(FunctionAssistant.class)
//                .chatLanguageModel(chatLanguageModel)//大模型
//                .tools(Map.of(toolSpecification, toolExecutor))//函数
//                .build();
//    }

    @Bean
    public FunctionAssistant functionAssistant(ChatLanguageModel chatLanguageModel) {

        return AiServices.builder(FunctionAssistant.class)
                .chatLanguageModel(chatLanguageModel)
                .tools(new InvoiceHandler())
                .build();
    }

}

